<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
%>
<form id="form_group_input" class="form-horizontal">
  <input type="hidden" name="keyId" id="keyId" value="${keyId}"/>
  <div id="container_group_input">
    <div class="form-group">
      <label class="col-md-3 control-label">名称</label>
      <div class="col-md-7">
        <input type="text" name="name" id="name" placeholder="请输入名称"   value="${group.name}" class="form-control">
      </div>
    </div>
    <div class="form-group">
      <label class="col-md-3 control-label">别名</label>
      <div class="col-md-7">
        <input type="text" name="pName" id="pName" value="${group.pName}" class="form-control" placeholder="请输入别名">
      </div>
    </div>
    <div class="form-group">
      <label class="col-md-3 control-label">描述</label>
      <div class="col-md-7">
        <input type="text" name="description" id="description" value="${group.description}" class="form-control" placeholder="请输入群组描述">
      </div>
    </div>
    <div class="form-group">
      <label class="col-md-3 control-label">
        <a href="javascript:void(0);" style="color: #0a6dbd" onclick="fn_members_dialog_select('usersName', 'usersId')"  key="ajax_user_group_list">用户</a>
      </label>
      <div class="col-md-7">
        <input type="hidden" name="usersId" id="usersId" value="<c:forEach items="${group.usersSet}" varStatus="i" var="list" ><c:if test="${list.state.toString() == 'Enable'}">${list.id}<c:if test="${!i.last}">,</c:if></c:if></c:forEach>" >
        <input  id="usersName" placeholder="请选择" disabled class="form-control"
                type="text" value="<c:forEach items="${group.usersSet}" varStatus="i" var="list"><c:if test="${list.state.toString() == 'Enable'}">${list.name}<c:if test="${!i.last}">,</c:if></c:if></c:forEach>">
      </div>
    </div>
    <div class="form-group">
      <label class="col-md-3 control-label" >
        <a  href="javascript:void(0);" style="color: #0a6dbd" onclick="fn_departments_dialog_select('y','departName','departId')" key="ajax_depart_group_list">部门</a>
      </label>
      <div class="col-md-7">
        <input name="departId" id="departId"
               type="hidden" value="<c:forEach items="${group.departSet}" varStatus="i" var="list" ><c:if test="${list.state.toString() == 'Enable'}">${list.id}<c:if test="${!i.last}">,</c:if></c:if></c:forEach>">
        <input  id="departName" placeholder="请选择" disabled class="form-control"
                type="text" value="<c:forEach items="${group.departSet}" varStatus="i" var="list" ><c:if test="${list.state.toString() == 'Enable'}">${list.name}<c:if test="${!i.last}">,</c:if></c:if></c:forEach>">
      </div>
    </div>
    <div class="form-group">
      <label class="col-md-3 control-label">
        <a  href="javascript:void(0);" style="color: #0a6dbd" onclick="fn_power_dialog_select('powerName', 'powerId')" key="ajax_post_group_list">职权</a>
      </label>
      <div class="col-md-7">
        <input name="powerId" id="powerId"
               type="hidden" value="<c:forEach items="${group.powerSet}" varStatus="i" var="list" ><c:if test="${list.state.toString() == 'Enable'}">${list.id}<c:if test="${!i.last}">,</c:if></c:if></c:forEach>">
        <input  id="powerName" placeholder="请选择" disabled class="form-control"
                type="text" value="<c:forEach items="${group.powerSet}" varStatus="i" var="list" ><c:if test="${list.state.toString() == 'Enable'}">${list.department.name}->${list.post.name}<c:if test="${!i.last}">,</c:if></c:if> </c:forEach>">
      </div>
    </div>
  </div>
</form>


<script>

  $(function(){
    // 表单数据校验
    fn_group_input_validate();


  });



  // 表单数据校验
  function fn_group_input_validate() {
    __init_validate('form_group_input', {
      rules : {
        name : {
          required : true
        },
        pName:{
          required : true
        }
      },
      messages : {
        name : {
          required : "请输入群组名称"
        },
        pName:{
          required : "请输入群组别名"
        }
      }
    });
  }

  function fn_group_input_save(callback) {
    if (!$("#form_group_input").valid()) {
      return false;
    }
    __confirm_dialog(null, '确定提交么?',
            function () {
              __form_save("form_group_input", "<%=path%>/main/group/save", function(data) {
                if(data.state == 1){

                  callback(data.data);
                } else {
                  callback();
                }
              });
            },
            function () {
              callback();
            }
    );
  }

  // 用户选择框
  function fn_members_dialog_select(nameField,idField) {

    __open_dialog_select('选择用户', '<%=path%>/main/member/dialogs?sids='+$("#"+idField).val(), function (dialogRef) {
      var callback = function (data) {
        if (data) {
          dialogRef.close();

          $('#'+idField).val(data.ids);
          $('#'+nameField).val(data.names);
        } else {
          dialogRef.enableButtons();
        }
      };
      fn_dialog_members_select(callback);
    });
  }

  // 部门选择框
  function fn_departments_dialog_select(isMulti,nameField,idField) {

    __open_dialog_select('选择部门', '<%=path%>/main/department/dialog?multi='+isMulti+'&deptIds='+ $('#'+idField).val(), function (dialogRef) {
      var callback = function (data) {
        if (data) {
          dialogRef.close();
          $('#'+idField).val(data.ids);
          $('#'+nameField).val(data.names);
        } else {
          dialogRef.enableButtons();
        }
      };
      fn_dialog_departments_select(callback);
    });
  }

  // 职权选择框
  function fn_power_dialog_select(nameField,idField) {

    __open_dialog_select('选择职权', '<%=path%>/main/power/dialogs?sids='+$("#"+idField).val(), function (dialogRef) {
      var callback = function (data) {
        if (data) {
          dialogRef.close();

          $('#'+idField).val(data.ids);
          $('#'+nameField).val(data.names);
        } else {
          dialogRef.enableButtons();
        }
      };
      fn_dialog_power_select(callback);
    });
  }


</script>